<!DOCTYPE html>
<html lang="en">
<head>
    <!-- 所谓单向数据流，实质上就是子组件存储父组件传递值，以达到对其进行改变的目的 -->
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://cdn.jsdelivr.net/npm/vue@2.6.14/dist/vue.js"></script>
</head>
<body>
    <div id="app">
        <p>{{ total }}</p>
        <mycom v-model="total"></mycom>
    </div>

    <template id="temp">
        <div>
            <button @click="add">+1</button>
        </div>
    </template>

    <script>
        Vue.component(
            'mycom', {
                template: '#temp',
                // props: ["value"],
                data() {
                    return {
                        count: 0
                    }
                },
                methods: {
                    add() {
                        this.count ++;
                        this.$emit('input', this.count)
                    }
                }
            }
        )

        new Vue({
            el: "#app",
            data: {
                total: 10
            }
        })
    </script>
</body>
</html>